package com.xqboss.apps.enums.user;

import com.xqboss.common.enums.BaseEnum;
import com.xqboss.common.exception.ServiceException;
import com.xqboss.common.utils.StringUtils;
import lombok.Getter;

import java.util.Objects;

public enum UserWalletEnum implements BaseEnum<Integer> {

    CASH(1, "现金钱包", null),

    INTEGRAL(2, "热豆钱包", "YXB01"),

    LIDOU(3, "力豆钱包",null ),

    WRENCH(10,"扳手钱包",null);


    private final Integer value;
    private final String msg;
    @Getter
    private final String code;

    UserWalletEnum(Integer value, String description, String code) {
        this.value = value;
        this.msg = description;
        this.code = code;
    }

    public Integer getValue() {
        return value;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public static UserWalletEnum parseByCode(String code){
        if(StringUtils.isNotEmpty(code)){
            for (UserWalletEnum value : UserWalletEnum.values()) {
                if(code.equals(value.getCode())){
                    return value;
                }
            }
        }
        return null;
    }

    public static UserWalletEnum valueOf(int value){
        for (UserWalletEnum enums : UserWalletEnum.values()) {
            if(Objects.equals(value, enums.getValue())){
                return enums;
            }
        }
        throw new ServiceException("类型错误~");
    }

}
